package co.fitstart.entity.courseware.fitnessgroup;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Type;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.courseware.dietary.DietaryProgramTemplate;
import co.fitstart.entity.courseware.dietary.DietaryProgramType;

@Entity
@Table(name = "batch_courseware_template")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class BatchCoursewareTemplate {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 名称 */
    private String name;
    
    /** 顺序 */
    private int sorting;
    
    /** 教练Tips */
    @Type(type = "text")
    @JSONField(serialize = false)
    private String coachTips;
    
    /** 课件类型 每周课件 or 课程课件*/
    @Enumerated(EnumType.ORDINAL)
    private BatchCoursewareType type;
    
    /** 早餐饮食计划 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private DietaryProgramTemplate breakfast;
    
    /** 午餐饮食计划 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private DietaryProgramTemplate lunch;
    
    /** 晚餐饮食计划 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private DietaryProgramTemplate dinner;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private FitnessGroup fitnessGroup;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public BatchCoursewareTemplate() {
        
    }
    
    /**
     * 
     * @param name
     * @param sorting
     * @param type
     * @param fitnessGroup
     */
    public BatchCoursewareTemplate(String name, int sorting, BatchCoursewareType type, FitnessGroup fitnessGroup) {
        this.name = name;
        this.sorting = sorting;
        this.type = type;
        this.fitnessGroup = fitnessGroup;
        this.disabled = false;
    }
    
    public BatchCoursewareTemplate(BatchCoursewareTemplate batchCoursewareTemplate, FitnessGroup fitnessGroup) {
        this.name = batchCoursewareTemplate.getName();
        this.sorting = batchCoursewareTemplate.getSorting();
        this.type = batchCoursewareTemplate.getType();
        this.breakfast = batchCoursewareTemplate.getBreakfast();
        this.lunch = batchCoursewareTemplate.getLunch();
        this.dinner = batchCoursewareTemplate.getDinner();
        this.fitnessGroup = fitnessGroup;
        this.disabled = batchCoursewareTemplate.isDisabled();
    }
    
    /**
     * 
     * @param template
     * @return
     */
    public BatchCoursewareTemplate edit(BatchCoursewareTemplate template) {
        this.breakfast = template.getBreakfast();
        this.lunch = template.getLunch();
        this.dinner = template.getDinner();
        return this;
    }
    
    /**
     * 
     * @return
     */
    public BatchCoursewareTemplate disable() {
        this.disabled = true;
        return this;
    }
    
    /**
     * 
     * @param dietaryProgramTemplate
     * @param dietaryProgramType
     * @return
     */
    public BatchCoursewareTemplate editDiet(DietaryProgramTemplate dietaryProgramTemplate, DietaryProgramType dietaryProgramType) {
        if(dietaryProgramType.isBreakfast()) {
            this.breakfast = dietaryProgramTemplate;
        } else if (dietaryProgramType.isLunch()) {
            this.lunch = dietaryProgramTemplate;
        } else if (dietaryProgramType.isDinner()) {
            this.dinner = dietaryProgramTemplate;
        }
        return this;
    }
    
    /**
     * 
     * @param tips
     * @return
     */
    public BatchCoursewareTemplate editTips(String tips) {
        this.coachTips = tips;
        return this;
    }
    
    /**
     * 
     * @param dietaryProgramType
     * @return
     */
    @Transient
    public DietaryProgramTemplate getDiet(DietaryProgramType dietaryProgramType) {
        if(dietaryProgramType.isBreakfast()) {
            return breakfast;
        } else if (dietaryProgramType.isLunch()) {
            return lunch;
        } else if (dietaryProgramType.isDinner()) {
            return dinner;
        }
        return null;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the sorting
     */
    public int getSorting() {
        return sorting;
    }

    /**
     * @return the coachTips
     */
    public String getCoachTips() {
        return coachTips;
    }

    /**
     * @return the type
     */
    public BatchCoursewareType getType() {
        return type;
    }

    /**
     * @return the breakfast
     */
    public DietaryProgramTemplate getBreakfast() {
        return breakfast;
    }

    /**
     * @return the lunch
     */
    public DietaryProgramTemplate getLunch() {
        return lunch;
    }

    /**
     * @return the dinner
     */
    public DietaryProgramTemplate getDinner() {
        return dinner;
    }

    /**
     * @return the fitnessGroup
     */
    public FitnessGroup getFitnessGroup() {
        return fitnessGroup;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param sorting the sorting to set
     */
    public void setSorting(int sorting) {
        this.sorting = sorting;
    }

    /**
     * @param coachTips the coachTips to set
     */
    public void setCoachTips(String coachTips) {
        this.coachTips = coachTips;
    }

    /**
     * @param type the type to set
     */
    public void setType(BatchCoursewareType type) {
        this.type = type;
    }

    /**
     * @param breakfast the breakfast to set
     */
    public void setBreakfast(DietaryProgramTemplate breakfast) {
        this.breakfast = breakfast;
    }

    /**
     * @param lunch the lunch to set
     */
    public void setLunch(DietaryProgramTemplate lunch) {
        this.lunch = lunch;
    }

    /**
     * @param dinner the dinner to set
     */
    public void setDinner(DietaryProgramTemplate dinner) {
        this.dinner = dinner;
    }

    /**
     * @param fitnessGroup the fitnessGroup to set
     */
    public void setFitnessGroup(FitnessGroup fitnessGroup) {
        this.fitnessGroup = fitnessGroup;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
